package main;

import java.awt.Rectangle;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.text.Element;
import javax.swing.text.IconView;

import view.DrawingView;
import model.DrawingModel;

public class GUI implements Runnable
{
	private DrawingModel model;
	
	public GUI(DrawingModel mod)
	{
		model = mod;
	}
	
	public void instantiate()
	{
		DrawingView view = new DrawingView(model);
		
		
		view.add(getButtonPanel(view));
		view.setLayout( new BoxLayout(view,BoxLayout.X_AXIS) );
		
		JFrame frm = new JFrame("CS456 - " + model.getFileName());
		view.setJFrame(frm);
		frm.setBounds(200, 200, 900, 600);
		frm.addWindowListener(view);
		frm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		frm.setJMenuBar(DrawingView.getMenu(view));
		frm.setContentPane(view);
		frm.setVisible(true);
	}
	
	private JPanel getButtonPanel(ActionListener view)
	{
		JPanel panel = new JPanel();
		
		Icon icon = new ImageIcon("icons/sel.png");
		JButton b1 = new JButton(icon);
		b1.setActionCommand("Select");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/text.png");
		b1 = new JButton(icon);
		b1.setActionCommand("Text");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/line.png");
		b1 = new JButton(icon);
		b1.setActionCommand("Line");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/curve.png");
		b1 = new JButton(icon);
		b1.setActionCommand("Curve");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/rect-e.png");
		b1 = new JButton(icon);
		b1.setActionCommand("EmptyRect");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/rect-f.png");
		b1 = new JButton(icon);
		b1.setActionCommand("FilledRect");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/ellipse-e.png");
		b1 = new JButton(icon);
		b1.setActionCommand("EmptyEllipse");
		b1.addActionListener(view);
		panel.add(b1);
		
		icon = new ImageIcon("icons/ellipse-f.png");
		b1 = new JButton(icon);
		b1.setActionCommand("FilledEllipse");
		b1.addActionListener(view);
		panel.add(b1);
		
		return panel;
	}
	
	@Override
	public void run()
	{
		instantiate();
	}

}
